package com.example.springsecurity.common.config;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description：权限验证配置类
 * @Author： fengcheng
 * @Date： 2025/1/17 13:53
 */
@Component("svc")
public class SecurityVerifyConfig {
    public boolean hasAuthority(String authority){
        //获取当前用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SystemUserLoginDetail loginUser = (SystemUserLoginDetail) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        //判断用户权限集合中是否存在authority
        return permissions.contains(authority);
    }
}
